package com.qidian.blog.service.impl;

import com.qidian.blog.factory.MapperFactory;
import com.qidian.blog.mapper.BlogCategoryMapper;
import com.qidian.blog.pojo.BlogCategory;
import com.qidian.blog.service.BlogCategoryService;
import com.qidian.blog.util.pojo.LayuiTableDTO;
import com.qidian.blog.util.pojo.QDResult;

import javax.servlet.annotation.WebServlet;

/**
 * @Author 郭浩
 * @Date 2022/10/10 19:34
 */
public class BlogCategoryServiceImpl implements BlogCategoryService {
    private BlogCategoryMapper mapper = MapperFactory.getMapper(BlogCategoryMapper.class);

    @Override
    public QDResult queryAll() {
        return QDResult.ok(mapper.queryAll());
    }

    @Override
    public QDResult save(BlogCategory blogCategory) {
        if (mapper.save(blogCategory)==1)
            return QDResult.ok();
        return QDResult.fal();
    }

    @Override
    public QDResult queryById(Long id) {
        return QDResult.ok(mapper.queryById(id));
    }

    @Override
    public QDResult update(BlogCategory blogCategory) {
        if (mapper.update(blogCategory)==1)
            return QDResult.ok();
        return QDResult.fal();
    }

    @Override
    public LayuiTableDTO<BlogCategory> queryByPage(int page, int limit, BlogCategory blogCategory) {
        LayuiTableDTO<BlogCategory> dto = new LayuiTableDTO<>();
        dto.setCode(0);
        dto.setMsg("");
        dto.setCount(mapper.count(blogCategory));
        dto.setData(mapper.queryByPage((page-1)*limit,limit,blogCategory));
        return dto;
    }

    @Override
    public QDResult delete(Long id) {
        return QDResult.ok(mapper.delete(id));
    }
}
